package ar.edu.sccs.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.List;

import ar.edu.sccs.model.loader.dto.DataClazz;
import ar.edu.sccs.monitoring.exception.SccsGenericException;

public class ObjectOutStream {

	private ObjectOutputStream file2write;

	public void writeDataClazzFile(String filePath, List<DataClazz> dataClazzList) throws SccsGenericException {
		try {
			createFile(filePath);
			for (DataClazz clazz : dataClazzList) {
				file2write.writeObject(clazz);
			}
		} catch (Exception e) {
			throw new SccsGenericException(e);
		} finally {
			closeFile();
		}
	}

	private void createFile(String filePath) throws Exception {
		file2write = new ObjectOutputStream(new FileOutputStream(new File(filePath)));
	}

	private void closeFile() {
		try {
			file2write.flush();
			file2write.close();
		} catch (Exception e) {
		}
	}
}
